import pandas as pd
import matplotlib.pyplot as plt

# 读取数据
nsga3_rl_df = pd.read_csv('pareto_front_nsga3_rl.csv')
nsga3_df = pd.read_csv('pareto_front_nsga3.csv')
pareto_points_df = pd.read_csv('pareto_points.csv')

# 对数据按Operation_Cost排序（确保连线顺序从左到右）
nsga3_rl_df = nsga3_rl_df.sort_values(by='Operation_Cost')
nsga3_df = nsga3_df.sort_values(by='Operation_Cost')
pareto_points_df = pareto_points_df.sort_values(by='Operation_Cost')

# 创建图形
plt.figure(figsize=(10, 6))

# 绘制NSGA3-RL点划线和散点
plt.plot(nsga3_rl_df['Operation_Cost'], nsga3_rl_df['Carbon_Emissions'], 
         color='blue', linestyle='--', marker='o', markersize=6, markerfacecolor='blue', 
         label='NSGA3-RL', linewidth=2)

# 绘制NSGA3点划线和散点
plt.plot(nsga3_df['Operation_Cost'], nsga3_df['Carbon_Emissions'], 
         color='red', linestyle='--', marker='o', markersize=6, markerfacecolor='red', 
         label='NSGA3', linewidth=2)

# 绘制Pareto Points点划线和散点
plt.plot(pareto_points_df['Operation_Cost'], pareto_points_df['Carbon_Emissions'], 
         color='green', linestyle='--', marker='o', markersize=6, markerfacecolor='green', 
         label='PSO', linewidth=2)

# 设置图表标题和坐标轴标签
plt.title('Pareto Front Comparison (Three Algorithms)')
plt.xlabel('Operation Cost (¥)')
plt.ylabel('Carbon Emissions (ton)')

# 添加图例
plt.legend()

# 显示网格
plt.grid(True)

# 保存图表到文件
plt.savefig('pareto_front_comparison_three_algorithms.png')

# 显示图表
plt.show()